package com.shp.utils;

/**
 * 密码工具类
 * @author ZWL
 * @Version: 1.0
 * @create: 2020/2/26 20:38
 */
public class PasswordUtil {

    private static String pattern = "abcdefghijklmnopqrstuvwxyzABCDEFJKLMNOPQRSTUVWXYZ0123456789";
    private static StringBuffer sb = new StringBuffer();
    /**
     * 产生随机密码
     * @param size 密码的字符数
     * @return 密码
     */
    public static String createPassword(int size){
        if(size > 0){
            int len = pattern.length();
            for (int i = 0; i < size; i++) {
                sb.append(pattern.charAt((int) Math.round(Math.random() * (len - 1))));
            }
            return sb.toString();
        }
        return "";
    }
}
